# Maintainer: Paul Moore <p.f.moore@gmail.com>

_realname=file
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.39
pkgrel=1
pkgdesc='Determine the type of a file from its contents (mingw-w64)'
arch=('any')
url='https://www.darwinsys.com/file/'
license=('BSD')
depends=(${MINGW_PACKAGE_PREFIX}-bzip2
         ${MINGW_PACKAGE_PREFIX}-libsystre
         ${MINGW_PACKAGE_PREFIX}-xz
         ${MINGW_PACKAGE_PREFIX}-zlib)
source=("ftp://ftp.astron.com/pub/file/${_realname}-${pkgver}.tar.gz"
        "0001-file-5.38-mingw-build.patch")
sha256sums=('f05d286a76d9556243d0cb05814929c2ecf3a5ba07963f8f70bfaaa70517fad1'
            '65e8ec923de7fed74ed3bf204a562e38a8b077b24dc3d1cce09578deba2b3667')
options=('strip' '!libtool' 'staticlibs')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-file-5.38-mingw-build.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-libseccomp

  make
}

check() {
  cd ${srcdir}/build-${CARCH}
  make -C tests check
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make install DESTDIR="${pkgdir}"

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
